package com.dragon.repository.domain.dto;

import com.dragon.repository.entity.PurchaseRequisition;
import com.dragon.repository.entity.RequisitionProduct;
import com.dragon.repository.entity.WorkflowJson;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.dragon.common.util.BeanUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Date;


/**
 * @author sy
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class PurchaseRequisitionDTO {

    private static final long serialVersionUID = 1L;

    private Integer id;

    @ApiModelProperty(value = "请购单编号")
    private String purchaseCode;

    @ApiModelProperty(value = "请购标题")
    private String title;

    @ApiModelProperty(value = "请购人id")
    private Integer adminId;

    @ApiModelProperty(value = "请购人部门id")
    private Integer departmentId;

    @ApiModelProperty(value = "请购经办人id")
    private Integer operatorId;

    @ApiModelProperty(value = "审核状态：0,未审核，1,审核通过，2审核未通过")
    private Integer status;

    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    @ApiModelProperty(value = "修改时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;

    @ApiModelProperty(value = "备注")
    private String remark;

    @ApiModelProperty(value = "请购单状态：0未生单1部分生单2已生单")
    private Integer requisitionState;

    @ApiModelProperty(value = "公司id")
    private Integer companyId;

    @ApiModelProperty(value = "请购总金额")
    private Double productPrice;

    @ApiModelProperty(value = "请购人名称")
    private String adminName;

    @ApiModelProperty(value = "请购人部门名称")
    private String departmentName;

    @ApiModelProperty(value = "经办人名称")
    private String operatorName;

    @ApiModelProperty(value = "请购物品list")
    private List<RequisitionProduct> requisitionProductList;

    @ApiModelProperty(value = "工作流json")
    private List<WorkflowJson> workflowJsonList;

    @ApiModelProperty(value = "采购单code")
    private String procurementCode;

    @ApiModelProperty(value = "采购单创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date procurementCreateTime;

    public PurchaseRequisitionDTO() {}

    public PurchaseRequisitionDTO(PurchaseRequisition entity) {
        BeanUtils.copyProperties(entity,this);
    }

    public static PurchaseRequisitionDTO convert(PurchaseRequisition entity) {
        return new PurchaseRequisitionDTO(entity);
    }

    public static List<PurchaseRequisitionDTO> convertList(List<PurchaseRequisition> list) {
        List<PurchaseRequisitionDTO> resultList = new ArrayList<>();
        for (PurchaseRequisition entity : list) {
            resultList.add(new PurchaseRequisitionDTO(entity));
        }
        return resultList;
    }}
